#include "animation.h"

Animation::Animation()
{ }

Animation::Animation(Sprite* pS, int begin, int end)
{	
    pSprite = pS;
    posNow = D3DXVECTOR2(pSprite->GetCoordinate_X(), pSprite->GetCoordinate_Y());
    waitTime = 0;
    if (begin < 0)
        indexBegin = 0;
    else if (begin >= pSprite->GetNumberSprite())
        indexBegin = pSprite->GetNumberSprite() - 1;
    else
        indexBegin = begin;
        
    if (end < 0)
        indexEnd = 0;
    else if (end >= pSprite->GetNumberSprite())
        indexEnd = pSprite->GetNumberSprite() - 1;
    else
        indexEnd = end;
        
    indexSprite = indexBegin;
    if (indexBegin < indexEnd)
        next = 1;
    else
        next = -1;
}

void Animation::Present(unsigned int gameTime, unsigned int timePerSprite, float scale, int transparent)
{	
    waitTime += gameTime;
    if (waitTime >= timePerSprite)
    {	
        waitTime = 0;
        if (indexSprite != indexEnd)
            indexSprite += next;
        else
            indexSprite = indexBegin;
    }
    pSprite->Draw(indexSprite, scale, transparent);
    return;
}

Animation::~Animation()
{ }